﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DLV.Utilities;

namespace DLV.Data.Entities
{
    public class DistrictController
    {
        public int InsertDistrict(DistrictInfo info)
        {
            return SQL.InsertDistrict(info.CityId, info.DistrictName);
        }
        public void UpdateDistrict(DistrictInfo info)
        {
            SQL.UpdateDistrict(info.DistrictId, info.CityId, info.DistrictName);
        }
        public void DeleteDistrict(DistrictInfo info)
        {
            DeleteDistrict(info.DistrictId);
        }
        public void DeleteDistrict(int districtId)
        {
            SQL.DeleteDistrict(districtId);
        }
        public DistrictInfo GetDistrict(int districtId)
        {
            return CBO.FillObject<DistrictInfo>(SQL.GetDistrict(districtId));
        }
        public List<DistrictInfo> ListDistrict()
        {
            return CBO.FillCollection<DistrictInfo>(SQL.ListDistrict());
        }
        public DataTable SelectDistrict()
        {
            return CBO.ConvertToDataTable(ListDistrict(), typeof(DistrictInfo));
        }
        public List<DistrictInfo> ListDistrictByCity(int cityId)
        {
            return CBO.FillCollection<DistrictInfo>(SQL.ListDistrictByCity(cityId));
        }

        public Dictionary<object, object> ListDistrictLookup()
        {
            var pages = ListDistrict();
            var dicpages = new Dictionary<object, object>();
            foreach (var info in pages)
                dicpages.Add(info.DistrictId, info.DistrictName);
            return dicpages;
        }
    }
}
